﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

using Mighty.Lib.Controls;
using Mighty.Lib.Document;

namespace Mighty
{
    public partial class MightyMainWindow
    {

        private void NewButton_Click(object sender, EventArgs e)
        {
            _docs.Add(DocumentRepository.New());
            AddNewEditorWindow(_docs[_docs.Count - 1]);
            GiveFocusToNewestTabPage(EditorTabControl.Controls.Count - 1);
        }

        private void GiveFocusToNewestTabPage(int count)
        {
            EditorTabControl.SelectTab(count);
            EditorTabControl.Controls[count].Controls[0].Focus();
        }

        public void IntegrateDocuments()
        {
            if (_docs.Count == 0) _docs.Add(_documentRepo.New());
            EditorTabControl.SuspendLayout();
            _docs.ForEach((IDocument doc) =>
            {
                AddNewEditorWindow(doc);
            });
            EditorTabControl.ResumeLayout();
        }

        private void AddNewEditorWindow(IDocument doc)
        {
            TabPage page = (TabPage)new DefaultDocumentTabPage(doc);
            this.Controls[EditorTabControl.Name].Controls.Add(page);
        }


    }
}
